#ifndef VTKMESHEXPORT_HPP
#define VTKMESHEXPORT_HPP

#include "meshTypes_fwd.hpp"
#include "tinyxml2.h"
#include <filesystem>
#include <iostream>
#include <memory>

/**
 * @brief Holds functions for import and export from and to VTK XML files
 * 
 */
namespace hms::vtk {

namespace fs = std::filesystem;
namespace xml = tinyxml2;

void meshToVtk( xml::XMLElement* data, const UniMesh& mesh );
void meshToVtk( xml::XMLElement* data, const RectMesh& mesh );
void meshToVtk( xml::XMLElement* data, const StructMesh& mesh );
void meshToVtk( xml::XMLElement* data, const Mesh& mesh );

template<typename MeshType>
void meshToVtk( xml::XMLDocument*, const MeshBase<MeshType>& );

/**
 * @brief Takes an XML document and writes a mesh to it. The mesh type depends
 * on the type the hms::MeshVariant is holding.
 * 
 * @param meshVar
 * 
 * Exposed here to allow further modification of the returned XML document,
 * especially adding calculation results as CellData/PolyData
 */
void meshToVtk( xml::XMLDocument*, const MeshVariant& );

std::unique_ptr<xml::XMLDocument> meshToVtk( const MeshVariant& );

void meshToVtk( const fs::path& meshPath, const MeshVariant&, bool boundary = true );
void meshToVtk(
	const fs::path& caseDir,
	const std::string& caseName,
	const MeshVariant&,
	bool boundary = true
);


void boundaryToXML( xml::XMLNode*, const MeshVariant& meshVar );

std::unique_ptr<xml::XMLDocument> boundaryToXML( const MeshVariant& meshVar );

void boundaryToXML( const fs::path& caseDir, const MeshVariant& );

void removeNonexistentPatches( xml::XMLNode*, const MeshVariant& meshVar );

}

#endif